package ui;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class MainFrame  extends JFrame{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MainFrame() {
		
	    setLayout(new GridLayout(0,2));
	    
	    JLabel l1 = new JLabel("Number of Robots: ");
	    final JTextField t1 = new JTextField();
	    
	    JLabel l2 = new JLabel("Map Number of Rows: ");
	    final JTextField t2 = new JTextField();
	    
	    JLabel l3 = new JLabel("Map Number of Columns: ");
	    final JTextField t3 = new JTextField();	    
	    
	    JLabel l4 = new JLabel("Obstacle Width: ");
	    final JTextField t4 = new JTextField();
	    
	    JLabel l5 = new JLabel("Obstacle Height: ");
	    final JTextField t5 = new JTextField();
	    
	    JButton b = new JButton("Generate Map");
	    b.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				int nr_of_robots = Integer.parseInt(t1.getText());
				int map_width = Integer.parseInt(t2.getText());
				int map_height = Integer.parseInt(t3.getText());
				int obstacle_width = Integer.parseInt(t4.getText());
				int obstacle_height = Integer.parseInt(t5.getText());
			
				Grid area = new Grid(nr_of_robots,map_width,map_height,obstacle_width,obstacle_height);
		        JFrame f = new JFrame();
		        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		        f.add(area);
		        f.setSize(1500,800);
		        f.setLocation(100,100);
		        f.setVisible(true);
				dispose();
			}
		});
	    
	    add(l1);add(t1);
	    add(l2);add(t2);
	    add(l3);add(t3);
	    add(l4);add(t4);
	    add(l5);add(t5);
	    add(b);
	    
	    
	    setLocation(300,200);	    
	    setVisible(true);
	    setSize(400, 400);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    
	}

	public static void main(String[] args) {
		new MainFrame();

	}

}
